package com.nbb.aop;


import com.nbb.common.util.ApiLogUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;

/**
 * Created by lxw on 2016/11/18.
 */
@Consumes
public class ApiLogPrintAspect {

    public Object reqParamsLogPrint(ProceedingJoinPoint joinPoint) throws Throwable {
        long beginTime = System.currentTimeMillis();
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                .getRequest();
        Object restObj;
        try {
            restObj = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            throw throwable;
        }
        long endTime = System.currentTimeMillis();
        ApiLogUtil.logCollection(request, restObj, beginTime, endTime);
        return restObj;
    }
}